<?php

//session_start();
$sessionID = $_COOKIE['PHPSESSID'];

if(isset($_POST['action']) != '' || isset($_GET['action']) != '') {
	if($_POST['action'] == '')
	{
		$action 	= $_GET['action'];
		$productID	= $_GET['productID'];
		$noJavaScript = 1;
	} else {
		$action 	= $_POST['action'];
		$productID	= $_POST['productID']; 
		$noJavaScript = 0;
	}
}
	
if (isset($action) == "addToBasket"){
	
	$query  = "SELECT * FROM film WHERE ID = " . $productID;
	$conn = oci_connect("Klimo", "123", "localhost/XE");
	$q = oci_parse($conn,$query);
	$result = oci_execute($q);
	$row = oci_fetch_array( $q, OCI_ASSOC );
	$productName		= $row['TYTUL_POL'];
	
	$query = "INSERT INTO KOSZYK (KOSZYK_SESJA, ID_FILMU) VALUES ('".$sessionID."', '".$productID."')";
	$conn = oci_connect("Klimo", "123", "localhost/XE");

	$q = oci_parse($conn,$query);
	$result = oci_execute($q) or die('error');
	oci_close($conn);

	$query2  = "SELECT * FROM koszyk WHERE ID_FILMU = " . $productID . " AND KOSZYK_SESJA = '" . $sessionID . "'";
	$conn = oci_connect("Klimo", "123", "localhost/XE");
	
	$q2 = oci_parse($conn,$query2);
	$result = oci_execute($q2) or die('error');
	oci_close($conn); 
	if ($noJavaScript == 1) {
		header("Location: ../movies.php");

	} else {
		echo ('<li id="productID_' . $productID . '"><h6><a href="inc/deletefrombasket.php?action=deleteFromBasket&productID=' . $productID . '"
		      onClick="return false;"><img src="images/delete.png" id="deleteProductID_' . $productID . '"></a> ' . $productName . '</h6></li>');
	}
        
}
?>